<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php if (!session_id()) session_start();date_default_timezone_set('PRC'); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>物料搜索</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="demo.css" rel="stylesheet" type="text/css" />
    <script src="scripts/boot.js" type="text/javascript"></script>
</head>
<body >
 <fieldset id="fd1" style="border: 1px solid gray;height: 70px">
        <legend><span>搜索</span></legend>
        <div  id='fm1'>
        <div class="fieldset-body">
         <span style="margin-left: 8px"> 关键字:</span> <input type="input" class='mini-textbox' id='key' style="width: "/>
         <span style="margin-left: 20px">  品牌:</span>  <input type="input" class='mini-textbox' id='brand' style="width: "/>
        <br/>
		<span>一级类别</span>
        <input id="type1" class="mini-combobox" style="width:150px;" textField="cat" valueField="catid" 
        onvaluechanged="onType1Changed" url="/goods/getCatAjax?type=1"
        showNullItem="true"/> 
        <span>二级类别</span>
        <input id="type2" class="mini-combobox" style="width:150px;" textField="cat" valueField="catid"  onvaluechanged="onType2Changed" /> 
        <span>三级类别</span>
        <input id="type3" class="mini-combobox" style="width:150px;" textField="cat" valueField="catid" /> 
        <a class="mini-button" onclick="search()" enabled="" id='query-bt'  style="margin-top: 5px">&nbsp;&nbsp;查询&nbsp;&nbsp;</a> <a href="/sap/goods_search2.php">使用过滤功能</a>
 </fieldset>
  
   
 <div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%;margin-top: 5px;overflow:auto;" plain="false"  buttons="#tabsButtons">

    <div title="明细" >
        <div id="datagrid1" class="mini-datagrid" style="height:530px;width: 100%;" idField="id"  allowResize="true"  
          allowCellEdit="true" allowCellSelect="true" multiSelect="true" allowCellValid="true" oncellvalidation=""  url='/goods/queryItemBygoodssearch' >
        <div property="columns">
           <div type="checkcolumn" ></div>  
           <div field="code"  headerAlign="center"  >物料编号</div>   
           <div field="name"  headerAlign="center"  >物料名称</div>    
           <div field="U_TypeOption"  headerAlign="center"  >规格 </div>
       </div>
    <!-- <div title="Tab2" iconCls="" >
        2
    </div> -->
    </div>
   </div>
 </div>


  <div id='editForm1'>
    <br/>
    <a class="mini-button" onclick="htmlClick()" enabled="" id='query-bt' >&nbsp;&nbsp;下载数据包&nbsp;&nbsp;</a>
    
  </div>
</body>
<script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
      
        grid.on("drawcell", function (e) {
        var record = e.record,
        column = e.column,
        field = e.field,
        value = e.value;
        });
        var type1 = mini.get("type1");
        var type2 = mini.get("type2");
        var type3 = mini.get("type3");
        function onType1Changed(e) {
            var id = type1.getValue();
             if(parseInt(id)>0){
            type2.setValue("");
            var url = "/goods/getCatAjax?type=2&pcatid="+id;
            type2.setUrl(url);
            type2.select(0);
            onType2Changed();
             }else{
            	 type2.setData(null);
            	 type3.setData(null);
		
                 }
        }
        function onType2Changed(e) {
            var id = type2.getValue();
            type3.setValue("");
            var url = "/goods/getCatAjax?type=3&pcatid="+id;
            type3.setUrl(url);
            type3.select(0);
        }

        function search(){
            var key = mini.get('key').getValue();
			var catid=0;
            var type1 = mini.get('type1').getValue();
            var type2 = mini.get('type2').getValue();
            var type3 = mini.get('type3').getValue();
            var brand = mini.get('brand').getValue();
			if(type3!='')
				catid = type3;
			else if (type2!='')
				catid = type2;
			else
				catid = type1;
			grid.load({'key':key,'catid':catid,'brand':brand});
        }

        var htmlContent = document.getElementById("htmlContent");
        function htmlClick() {
				var list = grid.getSelecteds();
				
				var str  = '';
				for(var i=0;i<list.length;i++){
					str+=list[i].code+',';
					
				}
          
        	mini.open({
        	    url: "/sap/goodsdownload.php",
        	    title: "下载数据包", width: 290, height: 150,
        	    onload: function () {
        	        var iframe = this.getIFrameEl();
        	        var data = { data: str};
        	        iframe.contentWindow.SetData(data);
        	    },
        	    ondestroy: function (action) {

        	        grid.reload();
        	    }
        	});
        }

        function download(){

       	 var model = mini.get("rbl").getValue();
         var type  = mini.get("rbl2").getValue();

        
         $.ajax({
             url: "/goods/download",
             data: { model: model,type:type},
             type: "post",
             dataType:'json',
             success: function (data) {
               window.open(data.path+data.file_name);
             },
             error: function (jqXHR, textStatus, errorThrown) {
                 alert(jqXHR.responseText);
             }
         });
         
            }
    </script>

</html>